﻿namespace 第六次作业
{
    public partial class Form21 : Form
    {
        public string[] str = new string[6];
        public Form21()
        {
            InitializeComponent();
        }
        public Form21(string[] s)
        {
            for (int i = 0; i < 6; i++)
            {
                str[i] = s[i];
            }
            InitializeComponent();
            textBox1.Text = str[0];
            textBox2.Text = str[1];
            textBox3.Text = str[2];
            textBox4.Text = str[3];
            textBox5.Text = str[4];
            textBox6.Text = str[5];
        }

        //添加学生记录
        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text == null|| textBox2.Text == null || textBox3.Text == null || textBox4.Text == null || textBox5.Text == null || textBox6.Text == null )
            {
                MessageBox.Show("输入不完整，请检查","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
            else
            {
                string sql = "insert into student_information values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "')";
                MessageBox.Show(sql);
                Dao dao = new Dao();
                int i = dao.Execute(sql);
                if(i > 0)
                {
                    MessageBox.Show("插入成功！");
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == null || textBox2.Text == null || textBox3.Text == null || textBox4.Text == null || textBox5.Text == null || textBox6.Text == null)
            {
                MessageBox.Show("输入不完整，请检查", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                string sql = "delete from student_information where school='" + str[0] + "'and id='" + str[1] + "'";
                Dao dao = new Dao();
                dao.Execute(sql);
                string sqll = "insert into student_information values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "')";
                Dao dao0 = new Dao();
                dao0.Execute(sqll);
            }

        }
    }
}
